package com.dao.Impl;

import com.dao.CardtypeDao;
import com.entity.Cardtype;
import com.util.JDBC;
import com.util.TransBean;

import java.util.List;
import java.util.Map;

/**
 * @author 沐白
 */
public class CardtypeDaoImpl implements CardtypeDao {
    @Override
    public int add(Cardtype ct) {
        return 0;
    }

    @Override
    public List<Cardtype> findAll() {
        return null;
    }

    @Override
    public Cardtype findById(int id) {
        return null;
    }

    @Override
    public int modify(Cardtype ct) {
        return 0;
    }

    @Override
    public int delete(int id) {
        return 0;
    }

    @Override
    public List<Cardtype> findSctn(int page, int count) {
        return null;
    }

    @Override
    public Cardtype findByLevelId(int levelId) {
        String sql = "SELECT id,`name`,`rank`,`status`,coefficient,`level` FROM `cardtype` " +
                "where `level`=?";
        List<Map> maps = JDBC.selectMap(sql, levelId);
        List<Cardtype> clist = TransBean.populate(Cardtype.class, maps);
        return clist.get(0);
    }

    @Override
    public double findByCoefficient(String name) {
        List<List> lists = JDBC.selectArray("select coefficient FROM `cardtype` " +
                "where `name`=?", name);
        return (Double) lists.get(0).get(0);
    }
    @Override
    public int findByLevel(String name) {
        List<List> lists = JDBC.selectArray("select coefficient FROM `level` " +
                "where `name`=?", name);
        return (Integer) lists.get(0).get(0);
    }

    @Override
    public List<Map> findAllCardType() {
        List<Map> list = JDBC.selectMap("select name,`rank`,level from cardtype");
        if (list.size()>0){
            return list;
        }else{

            return null;
        }
    }
}
